package com.maddox.relax.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Objects;

/**
 * 选取的文件分类
 * 照片
 * 视频
 */
public class ImageSet implements Serializable {

    public static final int TYPE_ALL_MEDIA = -10; //所有类型
    public static final int TYPE_ALL_IMAGE = -100;//图片类型
    public static final int TYPE_ALL_VIDEO = -200;//视频类型
    private static final long serialVersionUID = -6497470576831874198L;
    public int id = TYPE_ALL_MEDIA;//当前类型
    public String name;
    public String coverPath;
    public int count;
    public ImageInfo cover;
    public ArrayList<ImageInfo> imageInfos;
    public boolean isSelected = false;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ImageSet imageSet = (ImageSet) o;
        return id == imageSet.id &&
                Objects.equals(name, imageSet.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name);
    }

    public ImageSet copy() {
        ImageSet imageSet = new ImageSet();
        imageSet.name = this.name;
        imageSet.coverPath = this.coverPath;
        imageSet.cover = this.cover;
        imageSet.isSelected = this.isSelected;
        imageSet.imageInfos = new ArrayList<>();
        imageSet.imageInfos.addAll(this.imageInfos);
        return imageSet;
    }

    //筛选出图片
    public ImageSet copyOnlyImage() {
        ImageSet imageSet = new ImageSet();
        imageSet.name = this.name;
        imageSet.coverPath = this.coverPath;
        imageSet.cover = this.cover;
        imageSet.isSelected = this.isSelected;
        imageSet.imageInfos = new ArrayList<>();
        if (this.imageInfos != null && this.imageInfos.size() > 0) {

            for (ImageInfo imageInfo : this.imageInfos) {
                if (imageInfo.isVideo) {
                    continue;
                }
                ImageInfo info = imageInfo.copy();
                imageSet.imageInfos.add(info);
            }

        }
        return imageSet;
    }

    //筛选出视频
    public ImageSet copyOnlyVideo() {
        ImageSet imageSet = new ImageSet();
        imageSet.name = this.name;
        imageSet.coverPath = this.coverPath;
        imageSet.cover = this.cover;
        imageSet.isSelected = this.isSelected;
        imageSet.imageInfos = new ArrayList<>();
        if (this.imageInfos != null && this.imageInfos.size() > 0) {

            for (ImageInfo imageInfo : this.imageInfos) {
                if (imageInfo.isVideo) {
                    ImageInfo info = imageInfo.copy();
                    imageSet.imageInfos.add(info);
                }

            }

        }
        return imageSet;
    }

    public boolean isAllMedia() {
        return this.id == TYPE_ALL_MEDIA;
    }

    public boolean isAllVideo() {
        return this.id == TYPE_ALL_VIDEO;
    }

    public boolean isAllImage() {
        return this.id == TYPE_ALL_IMAGE;
    }


}
